#----------------------------------------------------------------------------------------
#
# A Mailer script that makes use of System.Net to send email with attachments
#
# Sample usage:
#    
#  PS> Send-Mail-With-Attachment 'your-email-address@domain.com' 'Hello world!' 'Filename.txt'
#
#----------------------------------------------------------------------------------------

function global:Send-Mail-With-Attachment([string] $to, [string] $subject, [string] $file){
  $filenameAndPath = (Resolve-Path .\$file).ToString()
  $from = 'Automated Powershell Mailer'

  [void][Reflection.Assembly]::LoadWithPartialName('System.Net') | out-null

  $message = New-Object System.Net.Mail.MailMessage($from, $to, $subject, $subject)
  $attachment = New-Object System.Net.Mail.Attachment($filenameAndPath, 'text/plain')
  $message.Attachments.Add($attachment)

  $smtpClient = New-Object System.Net.Mail.SmtpClient
  $smtpClient.host = 'mail.domain.com'
  $smtpClient.Send($message)
}